﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Pavilion.NodeDesigner
{
    public static class NewWayHelper
    {
        /// <summary>
        /// Gets ancestor of starting element
        /// </summary>
        /// <param name="parentType">Desired type of ancestor</param>
        public static DependencyObject GetAncestor(DependencyObject startingElement, Type parentType)
        {
            if (startingElement == null || startingElement.GetType() == parentType)
                return startingElement;
            else
                return GetAncestor(VisualTreeHelper.GetParent(startingElement), parentType);
        }

        /// <summary>
        /// Returns parent of starting element whose parent type is type
        /// </summary>
        /// <param name="startingElement"></param>
        /// <param name="type">parent type of desired element</param>
        /// <returns></returns>
        public static DependencyObject GetParentWhoseAncestorIsType(DependencyObject startingElement, Type type)
        {
            if (startingElement == null || VisualTreeHelper.GetParent(startingElement).GetType() == type)
                return startingElement;
            else
               return GetParentWhoseAncestorIsType(VisualTreeHelper.GetParent(startingElement), type);
        }
    }
}
